package org.sky.axis2.soap;

import java.util.Iterator;

import org.apache.axiom.om.OMAbstractFactory;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMFactory;
import org.apache.axiom.om.OMNamespace;

public class SoapService {

	public static OMElement requestSoap = null;

	public OMElement request(OMElement soapBody) {
		requestSoap = soapBody;

		Iterator it = requestSoap.getChildElements();
		OMElement issuerElement = (OMElement) it.next();
		OMElement serialElement = (OMElement) it.next();
		OMElement revocationDateElement = (OMElement) it.next();

		String issuer = issuerElement.getText();
		String serial = serialElement.getText();
		String revocationDate = revocationDateElement.getText();
		System.out.println("issuer=====" + issuer);
		System.out.println("serial=====" + serial);
		System.out.println("revocationDate=====" + revocationDate);
		OMFactory soapFactory = OMAbstractFactory.getOMFactory();
		OMNamespace omNs = soapFactory.createOMNamespace(
				"http://soap.axis2.sky.org", "");
		OMElement soapResponse = soapFactory.createOMElement("SoapResponse",
				omNs);

		OMElement soapIssuer = soapFactory.createOMElement("Issuer", omNs);
		soapIssuer.setText("issuer: " + issuer);
		soapResponse.addChild(soapIssuer);

		OMElement soapSerial = soapFactory.createOMElement("Serial", omNs);
		soapSerial.setText("serial: " + serial);
		soapResponse.addChild(soapSerial);

		OMElement soapRevokeDate = soapFactory.createOMElement("RevokeDate",
				omNs);
		soapRevokeDate.setText("RevocationDate: " + revocationDate);
		soapResponse.addChild(soapRevokeDate);
		soapResponse.build();

		return soapResponse;
	}

}